package cn.bigfire.compiler.dragon.appendixA.handwrite.inter;

import cn.bigfire.compiler.dragon.appendixA.handwrite.lexer.Token;
import cn.bigfire.compiler.dragon.appendixA.handwrite.symbols.Type;


/**

 单目运算符
 ! Not


 */
public class Unary extends Op {

    public Expr expr;

    public Unary(Token token, Expr expr) {
        super(token, null);
        this.expr = expr;
        type = Type.max(Type.Int, expr.type);
        if (type == null) {
            error("type error");
        }
    }

    public Expr gen(){
        return new Unary(token, expr.reduce());
    }

    @Override
    public String toString() {
        return token.toString() + " " + expr.toString();
    }
}
